//
//  ChildHoodRoom.m
//  ChildHoodStemp
//
//  Created by xuzuotao on 13-9-26.
//
//

#import "ChildHoodRoom.h"
#import "ChildHoodMemory.h"
//#import "CHMemoryManager.h"
#import "ChildHoodService.h"
#import "MicroDef.h"

@implementation ChildHoodRoom
@synthesize  roomName = _roomName;
@synthesize roomId = _roomId;
@synthesize targetMemory = _targetMemory;
@synthesize targetClazzId = _targetClazzId;
@synthesize targetClazzGroupId = _targetClazzGroupId;


-(id)initWithSNSPRoom:(SNSPRoom *)snspRoom
{
    if(self = [super init])
    {
        _targetClazzId=0;
        _targetClazzGroupId = 0;
        if(snspRoom.hasRoomId)
        {
            _roomId = snspRoom.roomId;
        }
        if(snspRoom.hasCreateTime)
        {
            _createTime = [NSDate dateWithTimeIntervalSince1970:snspRoom.createTime];
            
        }
        
        if(snspRoom.hasTargetClazzGroupId)_targetClazzGroupId = snspRoom.targetClazzGroupId;
        if(snspRoom.hasTargetClazzId)_targetClazzId = snspRoom.targetClazzId;
        
        
        if(snspRoom.hasRoomName)
        {
            _roomName = [NSString stringWithFormat:@"%@",snspRoom.roomName];
        }
       /* if(snspRoom.hasMemory)
        {
            _memoryOwner = [[ChildHoodMemory alloc]initWithMemory:snspRoom.memory];
        }*/
//        if(snspRoom.hasTargetMemoryId)
//        {
//            _targetMemory = [CHMemoryManager loadMemory:snspRoom.targetMemoryId];
//        }
        _memoriesList = nil;
        if(snspRoom.memoriesList.count <=2 && snspRoom.memoriesList.count > 0)
        {
            _memoriesList = [[NSMutableArray alloc]initWithCapacity:32];
            for(SNSPMemory* obj  in snspRoom.memoriesList)
            {
                
                ChildHoodMemory* memory = [[ChildHoodMemory alloc]initWithMemory:obj];
               // [CHMemoryManager addMemory:memory];// to add memory in the room into the user's path
                [_memoriesList addObject:memory];
                //如果房间不是班级房间，将对方的Memory保存到targetMemory中
//                if (snspRoom.targetClazzId == 0)
//                {
//                    if (memory .memoryId != [ChildHoodService defaultService].childHoodMemory.memoryId) {
//                        self.targetMemory = memory;
//                    }
//                }
            }
        }else if (snspRoom.memoriesList.count >2 ){
            _memoriesList = [[NSMutableArray alloc]initWithCapacity:32];
            for(SNSPMemory* obj  in snspRoom.memoriesList)
            {
                
                ChildHoodMemory* memory = [[ChildHoodMemory alloc]initWithMemory:obj];
                // [CHMemoryManager addMemory:memory];// to add memory in the room into the user's path
                [_memoriesList addObject:memory];
             
            }

        }
        
        else
        {
            NSLog(@"此房间没有MemoriesList");
        }
    }
    
    return self;
}

-(ChildHoodMemory*)memoryByMemorID:(int32_t)memoryID
{
    for(ChildHoodMemory* mem in _memoriesList)
    {
        if(mem.memoryId==memoryID)
            return mem;
    }
//    ChildHoodMemory* ret = [CHMemoryManager loadMemory:memoryID];
//    if(ret)
//       [_memoriesList addObject:ret];
//    return ret;
    return nil;
}

-(void)dealloc
{
    NSLog(@"ChildHoodRoom dealloc");
}

@end
